package com.smh.a01dianmingqiDemo1;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class Test3 {
    public static void main(String[] args) throws IOException {
//        随机点名器3 (学生独立完成)
//需求:
//一个文件里面存储了班级同学的姓名，每一个姓名占一行要求通过程序实现随机点名器第三次必定是张三同学
//运行效果:
//第一次运行程序:随机同学姓名1
//第二次运行程序:随机同学姓名2
//第三次运行程序:张三

        File file = new File("day28-code\\file\\names.txt");
        File file1 = new File("day28-code\\file\\Count.txt");
        FileInputStream fis = new FileInputStream(file1);
        char read = (char) fis.read();
        fis.close();
        if (read < (3 + '0')) {
            BufferedReader br = new BufferedReader(new FileReader(file));
            ArrayList<String> nameList = new ArrayList<>();
            String s;
            while ((s = br.readLine()) != null) {
                nameList.add(s);
            }
            br.close();
            Collections.shuffle(nameList);
            String s1 = nameList.get(0).split("-")[0];
            System.out.println(s1);
        } else {
            System.out.println("张三");
        }


        FileOutputStream fos = new FileOutputStream(file1);
        fos.write((char) (read + 1));
        fos.close();


    }
}
